package com.mydemo.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
public class ChatClientController {

    @Resource
    private ChatModel chatModel;



    private final ChatClient chatClient;
    public ChatClientController(ChatClient.Builder builder) {
        this.chatClient = builder.build();
    }

    @GetMapping("/chat/model")
    public String hello(@RequestParam(name="msg",defaultValue = "祖国万岁" )String msg){

        return chatModel.call(msg);
    }


    @GetMapping("/chat/client")
    public Flux<String> hello2(@RequestParam(name="msg",defaultValue = "祖国万岁" )String msg){

        Flux<String> result = chatClient.prompt(msg).stream().content();


        return result;
    }

}
